<?php
	class Database {
		function __construct($config=false) {
			if($config == false) {
				$this->config = new Config('database');
			} else {
				$this->config = $config;
			}
			$this->connect();
		}
		function connect() {
			$this->thread = mysql_connect($this->config->data['server'], $this->config->data['user'], $this->config->data['password']);
			mysql_select_db($this->config->data['database'], $this->thread);
		}
		function query($query) {
			if($query = mysql_query($query, $this->thread)) {
				return $query;
			} else {
				return array('failed' => true, 'message' => mysql_error($this->thread));
			}
		}
		function result($query, $index=0) {
			$result = $this->query($query);
			if($result['failed'] == true) {
				return false;
			} else {
				return mysql_result($this->query($query), $index);
			}
		}
		function fetch_array($query) {
			$result = $this->query($query);
			$data = array();
			if($result['failed'] == true) {
				return $result['message'];
			} else {
				while($tmpdata = mysql_fetch_assoc($result)) {
					$data[] = $tmpdata;
				}
				return $data;
			}
		}
	}
?>